﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Pixysoft.SQL
{
    public class SqlTable
    {
        string tablename;

        string columnname;

        public SqlTable(string tablename, string columnname)
        {
            this.tablename = tablename;
            this.columnname = columnname;
        }

        public SqlColumn Column
        {
            get
            {
                return new SqlColumn(tablename, columnname);
            }
        }

        public string AS(string columnname)
        {
            return string.Format("{0}.{1} AS {2}", this.tablename, this.columnname, columnname);
        }

        public string AS()
        {
            return string.Format("{0}.{1} AS {1}", this.tablename, this.columnname);
        }

        public string TableName
        {
            get { return tablename; }
        }

        public string ColumnName
        {
            get { return columnname; }
        }

        public override string ToString()
        {
            return tablename + "." + columnname;
        }

        public static implicit operator string(SqlTable c)
        {
            return c.tablename + "." + c.columnname;
        }
    }
}
